
#include <cstdlib>

#include "threading/AbstractThread.h"

AbstractThread::AbstractThread()
{
}

AbstractThread::~AbstractThread()
{
    pthread_cancel(threadId_);
}

int AbstractThread::exec()
{
    return pthread_create(&threadId_, NULL, moveToObject, (void*)this);
}

int AbstractThread::exit()
{
    return pthread_cancel(threadId_);
}

int AbstractThread::join()
{
    return pthread_join(threadId_, NULL);
}

void* AbstractThread::moveToObject(void *object)
{
    static_cast<AbstractThread*>(object)->run();
    pthread_exit(NULL);
}
